package com.ruoyi.biz.utils;

import com.ruoyi.biz.model.req.StatReq;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class ReqUtils {
    public static StatReq getReq(Integer year) {
        StatReq req = new StatReq();
        List<Date> times = new ArrayList<>();
        Calendar cal = Calendar.getInstance();
        // 设置为该年的第一天
        cal.set(year, Calendar.JANUARY, 1, 0, 0, 0);
        cal.set(Calendar.MILLISECOND, 0);
        times.add(cal.getTime());
        // 设置为该年的最后一天
        cal.set(year, Calendar.DECEMBER, 31, 23, 59, 59);
        cal.set(Calendar.MILLISECOND, 999);
        times.add(cal.getTime());
        req.setTimes(times);
        return req;
    }

    public static void setReq(StatReq req) {
        List<Date> times = new ArrayList<>();
        if (req.getTimes() == null || req.getTimes().isEmpty()) {
            Calendar cal = Calendar.getInstance();
            // 设置为该年的第一天
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
            times.add(cal.getTime());
        } else {
            times.add(req.getTimes().get(0));
        }
        if (req.getTimes() == null || req.getTimes().size() < 2) {
            times.add(new Date());
        } else {
            Calendar cal = Calendar.getInstance();
            cal.setTime(req.getTimes().get(1));
            cal.set(Calendar.HOUR_OF_DAY, 23);
            cal.set(Calendar.MINUTE, 59);
            cal.set(Calendar.SECOND, 59);
            cal.set(Calendar.MILLISECOND, 999);
            times.add(cal.getTime());
        }
        req.setTimes(times);
    }
}
